package cwnu.sapphire.com.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cwnu.sapphire.com.entity.Score;
import cwnu.sapphire.com.mapper.ScoreMapper;
import cwnu.sapphire.com.service.ScoreService;
import cwnu.sapphire.com.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ScoreServiceImpl extends ServiceImpl<ScoreMapper, Score> implements ScoreService {
    @Autowired
    private ScoreMapper scoreMapper;

    @Override
    public List<Score> list() {
        return scoreMapper.selectList(null);
    }

    @Override
    public Score getById(Integer id) {
        return scoreMapper.selectById(id);
    }

    @Override
    public boolean save(Score score) {
        // 设置默认值
        score.setDeleteFlag(0);
        Date beijingTime = TimeUtils.getBeijingTime();
        score.setCreateTime(beijingTime);
        score.setUpdateTime(beijingTime);
        return scoreMapper.insert(score) > 0;
    }

    @Override
    public boolean updateById(Score score) {
        score.setUpdateTime(new Date());
        return scoreMapper.updateById(score) > 0;
    }

    @Override
    public boolean removeById(Integer id) {
        return scoreMapper.deleteById(id) > 0;
    }
}
